import { createBrowserRouter, Navigate } from "react-router";

import Login from '@/pages/login/index.jsx'
import Home from '@/pages/home/index.jsx'
import Test from '@/pages/test/index.jsx'
import AuthRoute from '@/components/AuthRoute.jsx'
import User from '@/pages/user/index.jsx'
import Role from '@/pages/role/index.jsx'

const router = createBrowserRouter([
  {
    path: "/",
    element: (
      <AuthRoute>
        <Home />
      </AuthRoute>
    ),
    children: [
      { index: true, element: <Navigate to="/user" replace /> }, // 新增：默认重定向到/user
      { path: "user", element: <User /> },
      { path: "role", element: <Role /> }
    ]
  },
  {
    path: "/login",
    element: (
      <AuthRoute>
        <Login />
      </AuthRoute>
    ),
  },
  {
    path: "/test",
    element: (
      <AuthRoute>
        <Test />
      </AuthRoute>
    ),
  },
]);

export default router
